package jcl;

import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import static org.junit.Assert.assertTrue;

/**
 * Tests to see if MajorTom generates a random bearing on each turn.
 * 
 * @author Jerry Lau
 * 
 */
public class TestMajorTomRandomBearing extends RobotTestBed {

  boolean isRandom = false;
  double bearing = 0;
  double bearing2 = 0;

  /**
   * Gets the name of the robots which will battle.
   * 
   * @return The list of robots in the match.
   */
  public String getRobotNames() {
    return "sample.SittingDuck,jcl.MajorTom";
  }

  /**
   * Runs for 10 rounds.
   * 
   * @return Number of rounds
   */
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks if the robot uses the same bearing twice consecutively.
   * 
   * @param event Battle info
   */
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    if (bearing == 0) {
      bearing = robot.getBodyHeading();
    }
    else if (bearing != robot.getBodyHeading()) {
      bearing2 = robot.getBodyHeading();
      isRandom = true;
    }

  }

  /**
   * After battle, check to see if the two consecutive bearings were different and also prints the
   * bearings that were compared.
   * 
   * @param event Completed battle info
   */
  public void onBattleCompleted(BattleCompletedEvent event) {
    System.out.println(bearing + " is not equal to " + bearing2);
    assertTrue("Check if bearing was random...", isRandom);
  }

}
